package erp.education.server.beans.implementation.setup.school;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import erp.education.client.setup.school.SchoolRegRequest;
import erp.education.server.beans.implementation.BaseService;
import erp.education.server.beans.implementation.ResultResponse;
import erp.education.server.beans.implementation.ServiceObject;
import erp.education.server.beans.interfaces.setup.school.SchoolRegisterServiceI;
import erp.education.server.beans.interfaces.user.transaction.ServiceObjectI;
import erp.education.server.db.entites.setup.school.Schools;
import erp.education.server.db.exceptions.DbExceptions;
@Component("schoolRegisterService")
public class SchoolRegisterService extends BaseService implements SchoolRegisterServiceI {

	@Override
	public ServiceObjectI schoolRegisterLoadService(SchoolRegRequest schoolRegisterRequest) throws DbExceptions {
		ServiceObjectI response=new ServiceObject();
		ResultResponse holder=new ResultResponse();
		 List result=new ArrayList();
		result.add(schoolDao.getSchools());
		holder.setResultList(result);
		response.setResponseObject(holder); 
		return response;
	}


	@Override
	public ServiceObjectI saveUpdateSchoolDetails(SchoolRegRequest schoolRegisterRequest) throws DbExceptions {
		ServiceObjectI response=new ServiceObject();
		ResultResponse holder=new ResultResponse();
		 List result=new ArrayList();
		 Schools school=null;
		 school=schoolDao.getSchool(schoolRegisterRequest.getRegistrationId());
		 if(null==school){
			 school=new Schools();
			 school.setRegisterId(schoolRegisterRequest.getRegistrationId());
		 }
		 school.setSchoolName(schoolRegisterRequest.getSchoolName());
		 school.setEmailId(schoolRegisterRequest.getEmailId());
		 school.setFaxNo(schoolRegisterRequest.getFaxNo());
		 school.setPhoneNo(schoolRegisterRequest.getPhoneNo());
		 school.setRegDate(schoolRegisterRequest.getRegistrationDate());
		 schoolDao.merge(school);
		result.add(schoolDao.getSchools());
		holder.setResultList(result);
		response.setResponseObject(holder); 
		return response;
	}
}
